package com.net;

public class DoLogin{
  public static void main(String[] args) {
    ALogin a = new ALogin();
    a.start();

    BLogin b = new BLogin();
    b.start();

  }
}

class ALogin extends Thread {
  @Override
  public void run() {
    LoginServlet.doPost("a", "aa");

  }
}

class BLogin extends Thread {
  @Override
  public void run() {
    LoginServlet.doPost("b", "bb");

  }
}

class LoginServlet {
  private static String usernameRef;
  private static String passwordRef;

  synchronized public static void doPost(String username, String password) {
    try {
      usernameRef = username;
      if("a".equals(username)) {
        Thread.sleep(5000);
      }
      passwordRef = password;
      System.out.println("username="+usernameRef +" password="+passwordRef);

    }catch (Exception e) {
      e.printStackTrace();
    }
  }

}
